package com.tourism.website.articlemanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tourism.website.articlemanage.entity.Article;
import com.tourism.website.articlemanage.entity.ArticleCategory;
import com.tourism.website.articlemanage.mapper.ArticleCategoryMapper;
import com.tourism.website.articlemanage.service.IArticleCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tourismwebsite.articlemanage.dto.ArticleCategoryManageDTO;
import com.tourismwebsite.articlemanage.dto.ArticleManageDTO;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author kevin
 * @since 2024-06-11
 */
@Mapper(componentModel = "spring")
interface MsCategoryToAMapper {
    ArticleCategoryManageDTO ArticleToArticleManageDTO(ArticleCategory articleCategory);
}

@Service
public class ArticleCategoryServiceImpl extends ServiceImpl<ArticleCategoryMapper, ArticleCategory> implements IArticleCategoryService {


    @Resource
    MsCategoryToAMapper msCategoryToAMapper;

    @Override
    public List<ArticleCategoryManageDTO> queryCategoryToArticleID(Integer categoryId) {
        LambdaQueryWrapper<ArticleCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(ArticleCategory::getArticleId);
        wrapper.eq(ArticleCategory::getCategoryId, categoryId);
        List<ArticleCategory> articleCategories = baseMapper.selectList(wrapper);
        List<ArticleCategoryManageDTO> articleManageDTOS = articleCategories.stream()
                .map(ArticleCategory -> msCategoryToAMapper.ArticleToArticleManageDTO(ArticleCategory))
                .collect(Collectors.toList());
        return articleManageDTOS;
    }
}
    /*    @Override
        public List<ArticleCategoryManageDTO> queryCategoryToArticleID(Integer categoryId) {
            List<Integer> articleIds = articleCategoryMapper.queryCategoryToArticleID(categoryId);
            return articleIds.stream()
                    .map(ArticleManageDTO::new)
                    .collect(Collectors.toList());
        }*/